package com.cloud.drore.eboss.supplier.mapper;

import com.cloud.drore.eboos.common.base.MyMapper;
import com.cloud.drore.eboss.supplier.entity.ProductConsumeRelation;

import com.cloud.drore.eboss.supplier.entity.vo.ProductQueryVo;
import com.cloud.drore.eboss.supplier.mapper.provider.ProductConsumeRelationProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/2/2 16:07 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
public interface ProductConsumeRelationMapper extends MyMapper<ProductConsumeRelation> {

    @Select("select consume_id from eboos_product_consume_relation where is_deleted = '0' and  product_id ='${productId}' ")
    List<Long> selectConsumeIdByProductId(@Param("productId") Long productId);

    @SelectProvider(type = ProductConsumeRelationProvider.class, method = "selectRelationByParam")
    List<ProductConsumeRelation> selectRelationByParam(ProductConsumeRelation consumeRelation);

    //通过供应商的id查询eboos_product_consume_relation表中公共产品的id
    @Select("select  a.created_date,b.product_num,b.product_name as name\n" +
            "from  eboos_product_consume_relation a left join eboos_product b on a.product_id=b.id\n" +
            "where b.is_deleted =0 and  a.merchant_id=${id} and b.product_type!='COMBINATION_PRODUCT'\n")
    List<ProductQueryVo> queryProductList(@Param("id") Long id);

    @UpdateProvider(type = ProductConsumeRelationProvider.class, method = "updateProductConsumeRelationByParam")
    int updateProductConsumeRelationByParam(ProductConsumeRelation consumeRelation);
}